/**
 *  Copyright (c)  2011-2020 Panguso, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Panguso, 
 *  Inc. ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into with Panguso.
 */


package cn.edu.thu.log.util;

import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
/**
 * 
 * @author dongzihe
 *
 */
public final class FilePathChecker {
	
	private FilePathChecker() {
		super();
	}
	public static String dependencies(String hdfspath)  {
		String result = "";
		try {
			//FilePathChecker.getDirectoryFromHdfs();
			Configuration conf = new Configuration();
			FileSystem fs = FileSystem.get(URI.create(hdfspath), conf);
			if(fs.isDirectory(new Path(hdfspath))) {
				FileStatus[] fileList = fs.listStatus(new Path(hdfspath));
				int size = fileList.length;
				System.out.println("hello");
				for (int i = 0; i < size; i++) {
					System.out.println("name:"
							+ fileList[i].getPath().getName() + "/t/tsize:"
							+ fileList[i].getLen());
				}
			}
		} catch (Exception e) {
			System.out.println("");
		} finally {
			System.out.println("");
		}
		return result;
	}	
	/**
	 * 
	 * @param hdfspath parameter
	 * @return
	 */
	public static boolean isExist(String hdfspath) {
		boolean result = false;
		String dst = hdfspath;

		try {
			//FilePathChecker.getDirectoryFromHdfs();
			Configuration conf = new Configuration();
			FileSystem fs = FileSystem.get(URI.create(dst), conf);
			if (fs.exists(new Path(dst))) {
				result = true;
			} else {
				result = false;
			}
		} catch (Exception e) {
			System.out.println("");
		} finally {
			System.out.println("");
		}
		return result;
	}


}
